import logging  # 引入logging模块
import os
import time
class _log:
    def __init__(self,application):
        self.application = application
        self.logger = logging.getLogger()
        self.logger.setLevel(logging.INFO)  # Log等级总开关
        # 第二步，创建一个handler，用于写入日志文件
        self.rq = time.strftime('%Y%m%d%H%M', time.localtime(time.time()))
        self.log_path = os.path.dirname(os.getcwd()) + '/Logs/' + application
        self.pic_path = os.path.dirname(os.getcwd()) + '/Logs/' + application + "/运行截图"
        try:
            os.makedirs(self.log_path)
            os.makedirs(self.pic_path)
        except:
            pass
        self.logfile = self.log_path +'/'+ self.rq + '.log'
        self.fh = logging.FileHandler(self.logfile, mode='w')
        self.fh.setLevel(logging.DEBUG)
        self.formatter = logging.Formatter("%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s")
        self.fh.setFormatter(self.formatter)
        self.logger.addHandler(self.fh)
    def return_logfile(self):
        return self.logfile

    def return_logger(self):
        return self.logger